<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>打印配送标签</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <table width="100%" class="printTable" id="table0">
        <tr>
            <td width="100%"><span class="customer"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="distributionDate"></span></td>
        </tr>
        <tr>
            <td width="100%"><span class="foodName"></span></td>
        </tr>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var router = params.router;
    var routerName = params.routerName;
    var beginDistributionDate = params.beginDistributionDate;
    var mealsTypeId = params.mealsTypeId;
    var mealsTypeName = params.mealsTypeName;
    var foodMaterialTypeId = params.foodMaterialTypeId;
    var foodMaterialTypeName = params.foodMaterialTypeName;
    var foodMaterialId = params.foodMaterialId;
    var backAddress = params.backAddress;
    var printChoice = params.printChoice;
    function print() {
        $("#receiptPrintArea0").printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
            url: backAddress + "/api/order/queryRecipePrintLabel",
            data : JSON.stringify({
                "beginDistributionDate" : beginDistributionDate,
                "router" : router,
                "mealsTypeId" : mealsTypeId,
                "foodMaterialId" : foodMaterialId
            }),
            type: "post",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {
                beginDistributionDate = beginDistributionDate.substring(5)
                var index = data.data.length - 1;
                for (var i = 0 ; i < index ; i++) {
                    var node = $("#table0").clone(true);
                    $("#receiptPrintArea0").append($("<br/>"));
                    $("#receiptPrintArea0").append(node);
                }
                for (var i = 0 ; i < data.data.length ; i++) {
                    $(".distributionDate")[i].innerText = beginDistributionDate + ':' + data.data[i].routerName;
                    $(".customer")[i].innerText = data.data[i].customerName;
                    $(".foodName")[i].innerText = data.data[i].recipeTemplateName + '(' + data.data[i].totalAmount
                        + ')' ;
                }
                print()
            },
            error: function (status) {
                alert(status)
            }
        }
    )
</script>

</body>
</html>